<?php
namespace Admin\Controller;
use Admin\Controller\BaseController;
class ManagerlistController extends BaseController {
    public function index(){
    //管理员详情展示信息（显示5条）
    	$sql="select a.*,b.role_name from y_admin_member a left JOIN y_admin_role b on a.role_id = b.id order by add_time desc";
    	$M = M();
    	$admin_member=$M->query($sql);
        $M = M("admin_role");
        $role=$M->select();
    	$this->assign("admin_member",$admin_member);
        $this->assign("role",$role);
        $this->display();
    }
    //添加管理员方法
    public function add_admin(){
    	$M = M("admin_member");
    	$data= $M->create();
    	$password=md5($data["password"]);
    	$M->password = $password;
    	$M->add($admin_member);
    	redirect(U("Managerlist/index"),0,"页面跳转中···");
    } 
    //删除管理员方法
    public function delete_admin(){
        $M = M("admin_member");
        $data=I("get.");
        $id=$data["id"];
        $M->where("id='$id'")->delete();
        redirect(U("Managerlist/index"),0,"页面跳转中···");
    } 
    //编辑管理员方法
    public function edit_admin(){
        $data=I("get.");
        $id=$data["id"];
        $role_name=$data["role_name"];
        $sql="select a.*,b.role_name from y_admin_member a left JOIN y_admin_role b on a.role_id = b.id where a.id ='$id'";
        $M = M();
        $admin_member=$M->query($sql);
        $M = M("admin_role");
        $role=$M->select();
        $this->assign("admin_member",$admin_member);
        $this->assign("role",$role);
        $this->assign("role_name",$role_name);
        $this->display();
    } 
    //提交编辑方法
     public function edit_admin_do(){
        $data=I("post.");
        $id=$data["id"];
        $M = M("admin_member");
        $data= $M->create();
        $M->where("id=$id")->save($data);
        redirect(U("Managerlist/index"),0,"页面跳转中···");
    } 
    //密码修改
     public function edit_password(){
        $data=I("get.");
        $id=$data["id"];
        $M = M("admin_member");
        $admin_member=$M->where("id='$id'")->select();
        $this->assign("admin_member",$admin_member);
        $this->display();
    } 
    //密码提交 
     public function edit_password_do(){
        $data=I("post.");
        $id=$data["id"];
        $M = M("admin_member");
        $data= $M->create();
        $data["password"]=md5($data["password"]);
        $M->where("id=$id")->save($data);
        redirect(U("Managerlist/index"),0,"页面跳转中···");
    } 
}